﻿using System;
using System.Management;

namespace PlanningGIS.Util.Management
{
    /// <summary>
    /// 枚举打印机状态
    /// </summary>
    public enum PrinterStatus
    {
        /// <summary>
        /// 
        /// </summary>
        其他状态 = 1,
        /// <summary>
        /// 
        /// </summary>
        未知,
        /// <summary>
        /// 
        /// </summary>
        空闲,
        /// <summary>
        /// 
        /// </summary>
        正在打印,
        /// <summary>
        /// 
        /// </summary>
        预热,
        /// <summary>
        /// 
        /// </summary>
        停止打印,
        /// <summary>
        /// 
        /// </summary>
        打印中,
        /// <summary>
        /// 
        /// </summary>
        离线
    }
    
    /// <summary>
    /// 作用：打印机操作类
    /// </summary>
    public static class PrinterHelper
    {       
        /// <summary>
        /// 获取打印机的状态信息
        /// </summary>
        /// <param name="PrinterDevice">打印机名称</param>
        /// <returns>打印机状态</returns>
        public static PrinterStatus GetPrinterStatus(string PrinterDevice)
        {
            string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
            ManagementObject printer = new ManagementObject(path);
            printer.Get();
            PrinterStatus ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
            return ret;
        }

        /// <summary>
        /// 获取打印机的位置信息
        /// </summary>
        /// <param name="PrinterDevice">打印机名称</param>
        /// <returns>位置</returns>
        public static string GetPortName(string PrinterDevice)
        {
            string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
            ManagementObject printer = new ManagementObject(path);
            printer.Get();
            string ret = printer.Properties["PortName"].Value.ToString();
            return ret;
        }

        /// <summary>
        /// 获取打印机的类型(驱动)信息
        /// </summary>
        /// <param name="PrinterDevice">打印机名称</param>
        /// <returns>驱动信息</returns>
        public static string GetDriverName(string PrinterDevice)
        {
            string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
            ManagementObject printer = new ManagementObject(path);
            printer.Get();
            string ret = printer.Properties["DriverName"].Value.ToString();
            return ret;
        }
    }
}